<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册事件的兼容函数</title>
</head>
<body>
    <button id="btn">注册事件</button>
</body>
<script>
var btn = document.getElementById("btn");

eventResigter(btn,"click", fuc)

function eventResigter(ele,event,fuc){
    if(ele.addEventListener){
        ele.addEventListener(event, fuc);
    }else{
        ele.attachEvent('on' + event, fuc);
    }
}

function fuc(){
    alert("发生了点击事件！")
}
</script>
</html>